package com.styytech.dadabao.ui.my.accountset;


import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.lidroid.xutils.view.annotation.ContentView;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;
import com.styytech.dadabao.DadaApplication;
import com.styytech.dadabao.R;
import com.styytech.dadabao.base.BaseActivity;
import com.styytech.dadabao.utils.SpUser;
import com.styytech.dadabao.widge.dialog.IsInNumDialog;

/**
 * 安全设置
 */
@ContentView(R.layout.activity_safety_set)
public class SafetySetActivity extends BaseActivity {

    /*手机认证*/
    @ViewInject(R.id.llyt_phone_auth)
    LinearLayout llyt_phone_auth;
    /*手机认证已通过*/
    @ViewInject(R.id.tv_phone_passed)
    TextView tv_phone_passed;
    /*实名认证*/
    @ViewInject(R.id.llyt_name_auth)
    LinearLayout llyt_name_auth;
    /*实名认证立即验证*/
    @ViewInject(R.id.tv_name_auth)
    TextView tv_name_auth;
    /*交易密码*/
    @ViewInject(R.id.llyt_trader_password)
    LinearLayout llyt_trader_password;
    /*去设置交易密码*/
    @ViewInject(R.id.tv_trader_password)
    TextView tv_trader_password;


    /*上下文*/
    private Context mContext;
    private int idCardVStatus = 0;
    private int payforView = 0;//0:设置支付密码界面，1：修改支付密码界面
    IsInNumDialog isInNumDialog;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = this;
        initView();
    }

    /**
     * 初始化视图
     */
    private void initView() {
        DadaApplication.addActivity(this);
        setTopBar("安全设置", View.VISIBLE);

    }
    @Override
    protected void onResume() {
        super.onResume();
        initData();
    }


    /**
     * 初始界面设置
     */
    private void initData() {
        /*是否验证过*/
        idCardVStatus = SpUser.getIdCardVStatus(mContext);
        /*是否设置过交易密码*/
        payforView = SpUser.getBuyPasswordStatus(mContext);
        if (idCardVStatus == 1) {
            tv_name_auth.setText("已验证");
            tv_name_auth.setTextColor(getResources().getColor(R.color.hint_text));
        }
        if (payforView == 1) {
            tv_trader_password.setText("去修改");
            tv_trader_password.setTextColor(getResources().getColor(R.color.hint_text));
        }
    }

    @OnClick({R.id.llyt_phone_auth,
            R.id.llyt_name_auth,
            R.id.llyt_trader_password})
    public void click(View view) {
        switch (view.getId()) {
            case R.id.llyt_phone_auth:// 手机认证
                toast("您手机号已认证");
                break;
            case R.id.llyt_name_auth://实名认证
                if (idCardVStatus == 1) {
                    //真实姓名不能为空
                    toast("您已实名认证");
                    break;
                }
                showIsInDialog();
               // startNextActivity(AuthNameActivity.class);
                break;
            case R.id.llyt_trader_password://交易密码
                startNextActivity(PayforSetActivity.class);
                break;

        }
    }
    private void showIsInDialog(){
        isInNumDialog=new IsInNumDialog(this);
        isInNumDialog.setInCallBack(incallback);
        isInNumDialog.setOutCallback(outcallback);
        isInNumDialog.NotCancel(false);
        isInNumDialog.show();

    }
    IsInNumDialog.Dialogcallback incallback = new IsInNumDialog.Dialogcallback() {
        @Override
        public void dialogdo() {
            Intent intent = new Intent();
            intent.setClass(SafetySetActivity.this, AuthNameActivity.class);
            Bundle bundle = new Bundle();
            bundle.putInt("type", 1);
            intent.putExtras(bundle);
            startActivity(intent);
            isInNumDialog.dismiss();

        }
    };
    IsInNumDialog.Dialogcallback outcallback = new IsInNumDialog.Dialogcallback() {
        @Override
        public void dialogdo() {
            Intent intent = new Intent();
            intent.setClass(SafetySetActivity.this, AuthNameActivity.class);
            Bundle bundle = new Bundle();
            bundle.putInt("type", 2);
            intent.putExtras(bundle);
            startActivity(intent);
            isInNumDialog.dismiss();

        }
    };

    /**
     * 启动界面
     *
     * @param cls 需要启动的界面类
     */
    private void startNextActivity(Class<?> cls) {
        Intent intent = new Intent(mContext, cls);
        startActivity(intent);
    }

    /**
     * 提示消息
     *
     * @param str 需要提示的消息
     */
    private void toast(String str) {
        Toast.makeText(mContext, str, Toast.LENGTH_SHORT).show();
    }

}

